package main

import (
	"gin_web/controller"
	"gin_web/middleware"
	"github.com/gin-gonic/gin"
	"net/http"
)

func CollectRoute(r *gin.Engine) *gin.Engine {
	// 设置 cors
	r.Use(middleware.CORS())
	r.Use(middleware.Validation())
	// 设置 session
	r.Use(middleware.Session("sheeppp"))
	// 设置静态资源
	r.StaticFS("/assets", http.Dir("assets"))
	r.GET("/", func(ctx *gin.Context) {
		ctx.String(200, "hello gin")
	})

	authRoutes := r.Group("/auth")
	authController := controller.NewAuthController()
	authRoutes.GET("/captcha", authController.Captcha)
	authRoutes.GET("/captcha/verify/:value", authController.CaptchaVerify)
	authRoutes.POST("/register", authController.Register)
	authRoutes.POST("/login", authController.Login)

	userRoutes := r.Group("/user")
	userRoutes.Use(middleware.Auth())
	userController := controller.NewUserController()
	userRoutes.GET("/list", userController.PageList)
	userRoutes.GET("/get", userController.Get)
	userRoutes.POST("/save", userController.Save)
	userRoutes.POST("/remove", userController.Delete)
	return r
}
